﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using Graphene.Storing;

namespace Graphene
{
    public class Spat : HashSet<PointInt2D>
    {
        public Spat() {                               
            this.sumX = 0;
            this.sumY = 0;
        }

        public void MyAdd(PointInt2D p) {            
            if (p == null)
            {
                return ;
            }

            this.sumX += p.X;
            this.sumY += p.Y;
            base.Add(p);
        }

        /**
         * Returns the coordinates of the center of mass of the Spat.
         */ 
        public PointInt2D GetCenter() {
            int s = base.Count;
            if (s > 0) {
                return new PointInt2D((int)Math.Round((double)this.sumX / s), (int)Math.Round((double)this.sumY / s));                
            }

            return null;
        }

        public bool Contains(PointInt2D point)
        {
            return base.Contains(point);
        }


        /**
         * Sum of X coordinates of all possessed points.
         * It's for the center of mass.
         */ 
        private int sumX;
        
        /**
         * Sum of X coordinates of all possessed points.
         * It's for the center of mass.
         */ 
        private int sumY;
    }
}
